//
// Created by Administrator on 2024/6/10 0010.
//
#include <jni.h>
#include "RtspPlayer.h"

extern "C" {
JNIEXPORT jlong JNICALL
Java_com_example_helloffmpeg_system_RtspPlayer_nativeInit(JNIEnv *env, jobject thiz) {
    RtspPlayer *player = new RtspPlayer();
    return long (player);
}

JNIEXPORT void JNICALL
Java_com_example_helloffmpeg_system_RtspPlayer_nativeRelease(JNIEnv *env, jobject thiz, jlong nativeHandle) {
    RtspPlayer *player = (RtspPlayer *) nativeHandle;
    delete player;
}

JNIEXPORT jboolean JNICALL
Java_com_example_helloffmpeg_system_RtspPlayer_nativeOpenStream(JNIEnv *env, jobject thiz, jlong nativeHandle, jstring url) {
    RtspPlayer *player = (RtspPlayer *) nativeHandle;
    const char *urlStr = env->GetStringUTFChars(url, nullptr);
    bool result = player->openStream(urlStr);
    env->ReleaseStringUTFChars(url, urlStr);
    return result ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT void JNICALL
Java_com_example_helloffmpeg_system_RtspPlayer_nativeDecodeAndPlay(JNIEnv *env, jobject thiz, jlong nativeHandle, jobject surface) {
    RtspPlayer *player = (RtspPlayer *) nativeHandle;
    player->decodeAndPlay(env, surface);
}
}
